home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / 42 ƒ / G4Monitor.s < prev    next >
Encoding:
Text File  |  1999-06-25  |  5.0 KB  |  228 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        604Performance.s
  3. ;
  4. ;    Contains:    604 Performance Code
  5. ;
  6. ;    Written by: dgc = Douglas George Clarke
  7. ;
  8. ;    Copyright:    © 1995 by Apple Computer, Inc., All Rights Reserved.
  9. ;
  10.  
  11.  
  12. ;******************************************************************************************
  13. ;
  14. ; Macro definitions used throughout the file
  15. ;
  16.  
  17. ;
  18. ; Makecsect - Creates a new program section.
  19. ;
  20.  
  21.                     MACRO
  22.                     makecsect    &name
  23.                     
  24.                     csect         &name.[pr]                    
  25.                     function    &name.[pr]
  26.  
  27.     
  28.                     ENDM
  29.  
  30. ;
  31. ; Makeexport - Exports the specified name so that other object files can reference it.
  32. ;
  33.                     MACRO
  34.                     makeexport    &name
  35.                 
  36. &name                export        &name
  37.  
  38.                      ENDM
  39.  
  40. ;
  41. ; C_PROLOGUE - Glue code used to set up our environment when we get called from C.
  42. ;
  43.  
  44.                     MACRO
  45.                     C_PROLOGUE &spaceToSave
  46.  
  47.                      mflr    r0                            ;get link register
  48.                     stw        r0,0x0008(SP)                ;store the link resgister on the stack
  49.                     stwu    SP,-&spaceToSave(SP)        ;skip over the stack space where the caller
  50.                                                         ;  might have saved stuff
  51.                     ENDM
  52.         
  53. ;
  54. ; C_EPILOGUE - Glue code used to tear down our environment when we return to C.
  55. ;
  56.  
  57.                     MACRO
  58.                     C_EPILOGUE &spaceToRestore
  59.  
  60.                     lwz        r0, 0x8+&spaceToRestore(SP)    ;get the saved link register
  61.                     addic    SP,SP,&spaceToRestore        ;reset the stack pointer
  62.                     mtlr    r0                            ;reset the link register
  63.                     blr                                    ; return via the link register
  64.  
  65.                     ENDM
  66.  
  67.  
  68. ;******************************************************************************************
  69. ;
  70. ; Table of contents (TOC) entries
  71. ;
  72.  
  73.                     tc        .G4GetPMC[tc],.G4GetPMC                
  74.                     tc        .G4ClearPMC[tc],.G4ClearPMC                
  75.                     tc        .G4SetMMCR0[tc],.G4SetMMCR0                
  76.  
  77.  
  78. ;******************************************************************************************
  79. ;
  80. ; void G4GetPMC( long *PMC1, long *PMC2, long *PMC3, long *PMC4)
  81. ;
  82. ; Copy the PMC Registers into the longs pointed at by PMC1 and PMC2
  83. ;
  84.  
  85.                     makecsect    .G4GetPMC
  86.                     makeexport    .G4GetPMC
  87.  
  88. ;
  89. ; High memory
  90. ;
  91.  
  92. numFPRs:            set        0        ; num non-volatile FPRs (FPRs 14-31) we use
  93. numGPRs:            set        0        ; num non-volatile GPRs (GPRs 13-31) we use
  94. CalleesLocalVars:     set        0        ; we do not have any
  95. CalleesParams:        set        32        ; always leave space for GPRs 3-10
  96. linkageArea:        set        24        ; constant comes from the PowerPC Runtime Architecture Document
  97.  
  98. ;
  99. ; Low memory
  100. ;
  101.  
  102. saveSpace:            set        linkageArea + CalleesParams + CalleesLocalVars + 4*numGPRs + 8*numFPRs  
  103. gprsBase:            set     linkageArea + CalleesParams + CalleesLocalVars
  104.  
  105.  
  106.                     C_PROLOGUE saveSpace
  107.  
  108. ReadCounters:
  109.             mfspr    r7,953
  110.             stw        r7,0(r3)
  111.  
  112. ;            mfspr    r7,954
  113. ;            stw        r7,0(r4)
  114.  
  115. ;            mfspr    r7,957
  116. ;            stw        r7,0(r5)
  117.  
  118. ;            mfspr    r7,958
  119. ;            stw        r7,0(r6)
  120.  
  121.                     C_EPILOGUE saveSpace                ;this tears down the stack and returns via a blr
  122.  
  123. ;******************************************************************************************
  124. ;
  125. ; void G4ClearPMC( void)
  126. ;
  127. ; Clear the PMC1 Registers
  128. ;
  129.  
  130.                     makecsect    .G4ClearPMC
  131.                     makeexport    .G4ClearPMC
  132.  
  133. ;
  134. ; High memory
  135. ;
  136.  
  137. numFPRs:            set        0        ; num non-volatile FPRs (FPRs 14-31) we use
  138. numGPRs:            set        0        ; num non-volatile GPRs (GPRs 13-31) we use
  139. CalleesLocalVars:     set        0        ; we do not have any
  140. CalleesParams:        set        32        ; always leave space for GPRs 3-10
  141. linkageArea:        set        24        ; constant comes from the PowerPC Runtime Architecture Document
  142.  
  143. ;
  144. ; Low memory
  145. ;
  146.  
  147. saveSpace:            set        linkageArea + CalleesParams + CalleesLocalVars + 4*numGPRs + 8*numFPRs  
  148. gprsBase:            set     linkageArea + CalleesParams + CalleesLocalVars
  149.  
  150.                 
  151.                     C_PROLOGUE saveSpace
  152.  
  153. ClearCounters:
  154.             li        r5,0
  155.             mtspr    953,r5
  156. ;            mtspr    954,r5
  157. ;             mtspr    957,r5
  158. ;             mtspr    958,r5
  159.  
  160.                     C_EPILOGUE saveSpace                ;this tears down the stack and returns via a blr
  161.  
  162. ;******************************************************************************************
  163. ;
  164. ; void G4SetMMCR0( long    MMCR0, long MMRC1, long MMCR2)
  165. ;
  166. ; Build the MMCR0 word and store it in the MMCR0
  167. ;
  168.  
  169.                     makecsect    .G4SetMMCR0
  170.                     makeexport    .G4SetMMCR0
  171.  
  172. ;
  173. ; High memory
  174. ;
  175.  
  176. numFPRs:            set        0        ; num non-volatile FPRs (FPRs 14-31) we use
  177. numGPRs:            set        0        ; num non-volatile GPRs (GPRs 13-31) we use
  178. CalleesLocalVars:     set        0        ; we do not have any
  179. CalleesParams:        set        32        ; always leave space for GPRs 3-10
  180. linkageArea:        set        24        ; constant comes from the PowerPC Runtime Architecture Document
  181.  
  182. ;
  183. ; Low memory
  184. ;
  185.  
  186. saveSpace:            set        linkageArea + CalleesParams + CalleesLocalVars + 4*numGPRs + 8*numFPRs  
  187. gprsBase:            set     linkageArea + CalleesParams + CalleesLocalVars
  188.  
  189.  
  190. PMC1Select            set        r3
  191. PMC2Select            set        r4
  192.                 
  193.                     C_PROLOGUE saveSpace
  194.  
  195. SetTheMMCRO:
  196.             mtspr    952,r3
  197.  
  198. ;            mtspr    956,r4
  199.  
  200. ;             mtspr    944,r5
  201.  
  202.                     C_EPILOGUE saveSpace                ;this tears down the stack and returns via a blr
  203.  
  204. ;******************************************************************************************
  205. ;
  206. ; TVector for InternalFlushCacheRangePPC
  207. ;
  208.  
  209.                     EXPORT    G4GetPMC[ds]
  210. G4GetPMC            csect    G4GetPMC[ds]
  211.                     dc.l    .G4GetPMC
  212.                     dc.l    TOC[tc0]
  213.                     dc.l    0
  214.  
  215.                     EXPORT    G4ClearPMC[ds]
  216. G4ClearPMC            csect    G4ClearPMC[ds]
  217.                     dc.l    .G4ClearPMC
  218.                     dc.l    TOC[tc0]
  219.                     dc.l    0
  220.  
  221.                     EXPORT    G4SetMMCR0[ds]
  222. G4SetMMCR0            csect    G4SetMMCR0[ds]
  223.                     dc.l    .G4SetMMCR0
  224.                     dc.l    TOC[tc0]
  225.                     dc.l    0
  226.  
  227.                     END
  228.